function getJson(Url) {
    var a;
    $.ajax({
        url: Url,
        type: 'get',
        async: false,//true 异步提交，false 同步提交
        dataType: "json",
        success: function (data) {
            a = data;
        }
    });
    return a;
}

function getGetParaments(url) {
    var $_GET = [];
    var paramList = url.split('?');
    if (typeof (paramList[1]) == 'string') {
        paramList = paramList[1].split('&');
        for (i = 0; i < paramList.length; i++) {
            s = paramList[i].split("=");
            eval('$_GET["' + s[0] + '"]' + '="' + s[1] + '"');
        }
    }
    return $_GET
}

function GetBoxPic() {
    var img_goods = new Image();
    img_goods.src = "./image/Box.png"
    g_BoxPicList[0] = img_goods.cloneNode();
    img_goods.src = "./image/AirDrop.png"
    g_BoxPicList[1] = img_goods.cloneNode();
    return g_BoxPicList;
}

function getPortName() {
    var curUrl = window.location.toString();
    if (curUrl.indexOf("?") == -1) {	//无参数，默认返回本人  1
        return "TEST"
    }
    var param = getGetParaments(curUrl)
    for (var key in param) {
        return key;
        break;
    }
}


function getRoleName() {
    var curUrl = window.location.toString();
    if (curUrl.indexOf("?") == -1) {	//无参数，默认返回本人  1
        return "1"
    }
    var param = getGetParaments(curUrl)
    if (!param['id']) {
        return "1"
    }
    return param['id']
}

function getServerAddr() {
    var curUrl = window.location.toString();
    if (curUrl.indexOf("?") == -1) {	//无参数，默认返回本人  1
        return window.location['hostname']
    }
    var param = getGetParaments(curUrl)
    if (!param['addr']) {
        return window.location['hostname']
    }
    return param['addr']
}

function unzip(b64Data) {
    var strData = atob(b64Data);
    // Convert binary string to character-number array
    var charData = strData.split('').map(function (x) {
        return x.charCodeAt(0);
    });
    // Turn number array into byte-array
    var binData = new Uint8Array(charData);
    // // unzip
    var data = pako.inflate(binData);
    // Convert gunzipped byteArray back to ascii string:
    strData = Utf8ArrayToStr(data);
    return strData;
}

function zip(str) {
    var binaryString = pako.gzip(str, {to: 'string'});
    return btoa(binaryString);
}

function Utf8ArrayToStr(array) { // 数据流转化为字符串, 兼容汉字
    var out = "", i = 0, len = array.length, char1, char2, char3, char4;
    while (i < len) {
        char1 = array[i++];
        // 当单个字节时, 最大值 '01111111', 最小值 '00000000' 右移四位 07, 00
        // 当两个字节时, 最大值 '11011111', 最小值 '11000000' 右移四位 13, 12
        // 当三个字节时, 最大值 '11101111', 最小值 '11100000' 右移四位 14, 14
        if (char1 >> 4 <= 7) {
            out += String.fromCharCode(char1);
        } else if (char1 >> 4 == 12 || char1 >> 4 == 13) {
            char2 = array[i++];
            out += String.fromCharCode(((char1 & 0x1F) << 6) | (char2 & 0x3F));
        } else if (char1 >> 4 == 14) {
            char2 = array[i++];
            char3 = array[i++];
            char4 = ((char1 & 0x0F) << 12) | ((char2 & 0x3F) << 6);
            out += String.fromCharCode(char4 | ((char3 & 0x3F) << 0));
        }
    }
    return out;
}